import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'assets/css/comm.scss'

import '@/plugin/swiper'
import '@/plugin/vueLazyLoad'
import '@/plugin/vant'

import * as filters from './filters/filters'

Vue.config.productionTip = false

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.directive('price', {
  bind: function (el) {
    el.addEventListener('input', () => {
      let price = el.value
      price = price.replace(/[^\d.]/g, '') //清除"数字"和"."以外的字符
      price = price.replace(/^\./g, '') //验证第一个字符是数字
      price = price.replace(/\.{2,}/g, '.') //只保留第一个, 清除多余的
      price = price.replace(/^(\d+)\.(\d\d).*$/, '$1.$2') //只能输入两个小数
      el.value = price
    })
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
